<?php

namespace App\Http\Controllers;

use App\Http\Services\UserService;
use App\User;
use Illuminate\Http\Request;

class IndexController extends Controller
{

    protected $userService;

    public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }

    /**
     * 通过注入request,就可以在方法中直接对request进行操作
     * @param Request $request
     * @return array
     * @author wangju 18-12-27 下午1:33
     */
    public function index(Request $request)
    {
        return eer();
        return $request->all();
    }

    /**
     * 注入User,在路由匹配过程中,就可以在数据库查到对应的id,注入的user模型
     * @param User $user
     * @return User
     * @author wangju 18-12-27 下午1:33
     */
    public function update(User $user)
    {
        return $user;
    }

    /**
     * 通过当前控制器注入的service进行操作
     * @param User $user
     * @return string
     * @author wangju 18-12-27 下午1:37
     */
    public function greet(User $user){
        return $this->userService->greetUser($user);
    }
}
